﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Dev.Control;
using SfcorpDLL.biz;
using SfcorpDLL.ety;
using TT.Module.sysLogin;

namespace Sfcorp
{
    public partial class MainTag : BaseFormDev
    {
        bizMainTag bzMainTag;
        public MainTag()
        {
            InitializeComponent();
        }

        private void MainTag_Load(object sender, EventArgs e)
        {
            bzMainTag = new bizMainTag(global.basSysPara);

            string sGridHead = "[CONTRACT_NO;业务单号],[BNS_STATUS_D;状态],[CNTR_COUNT;箱数],[O_AMOUNT;金额],[CUSTOMER_NAM;客户名称],[PORT_NAM;码头名称],[FEE_WAY_NAM;结算方式],[REC_NAM;办理人],[FEE_WAY_ID;结算方式],[CLIENT_CONTACT;联系方式],"
                         + "[I_E_ID;进出口],[I_E_NAM;进出口],[CONTRACT_DATE;业务单日期]";

            ggcLstCreateBns.GridView = this.gridView1;
            ggcLstCreateBns.GridView.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.Click;
            ggcLstCreateBns.ColumnsMappingCreate(sGridHead);
            this.winUtil.LoadGridLayout(ggcLstCreateBns);

            
            //网格不能编辑
            gridView1.OptionsBehavior.Editable = false;
            //RefreshDate();
            //this.ggcFeeInfo.QueryCellStyleInfo
            
        }

        public override Dev.Control.etyQuickKey RefreshDate()
        {
            this.Cursor = Cursors.WaitCursor;
            GetLastCreateBns();
            //GetLastDeleteBns();
            this.Cursor = Cursors.Default;
            return base.RefreshDate();
        }

        private void GetLastDeleteBns()
        {
            //srcLastDeleteBns.DataSource = bzMainTag.GetLastFrtAgyBns("D");
            //ggcLstDelBns.DataSource = srcLastDeleteBns;
            //ggcLstDelBns.GridView.BestFitColumns();
        }

        private void GetLastCreateBns()
        {
            IList<etyFrtAgyBns> ilBns = bzMainTag.GetLastFrtAgyBns("A");
            srcLastCreateBns.DataSource = ilBns;
            ggcLstCreateBns.DataSource = srcLastCreateBns;

            ggcLstCreateBns.AutoColumnWidth();
        }
        //查询业务单
        public override etyQuickKey F10()
        {
            LoadFrtAgy();
            return base.F10();
        }
        private void ggcLstCreateBns_DoubleClick(object sender, EventArgs e)
        {
            LoadFrtAgy();
        }

        private void LoadFrtAgy()
        {
            try{  splashScreenManager1.ShowWaitForm();}
            catch { }

            etyFrtAgyBns ey = srcLastCreateBns.Current as etyFrtAgyBns;
            if (ey == null)
                return;

            MainForm mainForm = this.MdiParent as MainForm;
            DevExpress.XtraBars.Docking2010.Views.BaseDocument document = null;
            Sfcorp.form.frmAgyBns frmBns;
            if (mainForm.Documents.TryGetValue("Bns", out document))
            {
                frmBns = document.Form as Sfcorp.form.frmAgyBns;
                frmBns.Close();
            }
            frmBns = new Sfcorp.form.frmAgyBns();
            frmBns.ContractNo = ey.CONTRACT_NO;
            frmBns.MOD_ID = "barBns";
            frmBns.MdiParent = this.MdiParent;
            frmBns.Show();
            try { splashScreenManager1.CloseWaitForm(); }
            catch { }
        }

        private void tbarRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            RefreshDate();
        }

        private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (gridView1.GetRow(e.RowHandle) == null)
                return;
            else
            {
                etyFrtAgyBns pe = gridView1.GetRow(e.RowHandle) as etyFrtAgyBns;
                switch(pe.BNS_STATUS_D)
                {
                    case "D":
                        e.Appearance.BackColor = Color.Silver;
                        break;
                    case "N":
                        e.Appearance.BackColor = Color.PaleGreen;
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
